<?php
if( empty( $_SESSION ) )
{
	session_start();
}
header("Content-Type: text/html; charset=utf-8",true);

include_once("../../includes/restrito.php");
include_once("../models/cls.idioma.php");
$oIdioma = new idioma();

if( ! empty( $_GET["acao"] ) )
{
	$acao = $_GET["acao"];
	
	switch( $acao )
	{	
		case "editar" :
			$oIdioma->select( $_GET["id"] );
			break;
			
		case "excluir" :
			$oIdioma->delete( $_GET["id_delete"], "../views/frm.idioma.php" );
			break;
	
		case "ativar" :
			$oIdioma->situacao( $_GET["id"] , $acao );
			break;

		default :
			$oIdioma->situacao($_GET["id"] , $acao );
			break;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IDIOMA</title>
<link rel="stylesheet" type="text/css" href="../../includes/sistema.css"/>
<script>
function _excluir(id)
{
	if(confirm("Por favor, confirme há remoção!"))
	{
		window.location.href="frm.idioma.php?id_delete=" + id + "&acao=excluir";
	}	
}

function _salvar(){
	if(document.frm.nome.value=="")
	{
		alert("Por favor, informe o nome do idioma!");
		document.frm.nome.focus();
		return;
	}
	if(document.frm.sigla.value=="")
	{
		alert("Por favor, informe a sigla do idioma!");
		document.frm.sigla.focus();
		return;
	}
	document.frm.submit();
}
</script>
</head>
<body>
<div id="content">
  <h2>Idioma</h2>
  <hr size="1" noshade="noshade">
    <form name="frm" method="post" action="../controllers/ctl.idioma.php">
      <table width="600" border="0" align="center">
        <tr>
          <td width="14%">Sigla:<br />            <input name="sigla" type="text" class="form50px" value="<?php echo $oIdioma->sigla; ?>" maxlength="2" /></td>
          <td width="86%">Situação:<br />
<select name="situacao" class="form100px">
          <option value="1" <?php if( $oIdioma->situacao == 1 ){ echo " selected"; } ?>>Ativar</option>
              <option value="0" <?php if( $oIdioma->situacao == 0 ){ echo " selected"; } ?>>Desativar</option>
          </select></td>
        </tr>
        <tr>
          <td colspan="2">Nome:
          <input name="nome" type="text" class="form100pc" value="<?php echo $oIdioma->nome; ?>" /></td>
        </tr>
        <tr>
          <td colspan="2"><input name="id" type="hidden" value="<?php echo $oIdioma->id; ?>" />            <input name="btnSubmit" type="button" class="formButton" value="SALVAR" onclick="_salvar()" /></td>
        </tr>
      </table>
<hr size="1" noshade="noshade">
    </form>    
<?php
$cor=true;
$aIdioma = $oIdioma->select();

echo '<table width=100%>';
echo '<th align="left">NOME</th>';
echo '<th align="center">SIGLA</th>';
echo '<th align="center">SITUAÇÃO</th>';
echo '<th align="center">EDITAR</th>';
echo '<th align="center">EXCLUIR</th>';

foreach($aIdioma as $sItem) // VARRE A LISTA E IMPRIME OS ÍNDICES DA COLEÇÃO
{
	// ALTERNA AS CORES DA LINHA DA TABELA A CADA REGISTRO IMPRESSO
	if($cor)
	{
		$tdcor = "#F4F4F4"; //CINZA CLARO
		$cor=false;
	}
	else{
		$tdcor = "#FFFFFF"; //BRANCO
		$cor = true;
	}
	
	echo '<tr bgcolor="'. $tdcor .'">';

	switch( $sItem["sigla"] )
	{
		case "BR" :
			$icon = "br.gif";
			break;
		case "ES" :
			$icon = "es.gif";
			break;
		case "FR" :
			$icon = "fr.gif";
			break;
		case "DE" :
			$icon = "de.gif";
			break;
		case "US" :
			$icon = "us.gif";
			break;
		case "NL" :
			$icon = "nl.gif";
			break;
		case "IT" :
			$icon = "it.gif";
			break;
		default :
			$icon = "world.gif";
			break;
	}
	echo '<td><a href="frm.idioma.configuracao.php?id='. $sItem['id'] .'&nome=' . $sItem['nome'] . '"><img src="../imagens/' . $icon . '" border="0"> ' . $sItem['nome'] . '</a></td>';
	echo '<td width="10%" align="center">' . $sItem["sigla"] . '</td>';
	
	if($sItem["situacao"] == 0)
	{
		echo '<td width="10%" align="center"><a href="frm.idioma.php?id=' . $sItem["id"] . '&acao=ativar"><img src="../imagens/ativar.out.png" border="0"></a></td>';
	}
	else
	{
		echo '<td width="10%" align="center"><a href="frm.idioma.php?id=' . $sItem["id"] . '&acao=desativar"><img src="../imagens/ativar.png" border="0"></a></td>';
	}
	echo '<td width="10%" align="center"><a href="frm.idioma.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" border="0"></a></td>';
	echo '<td width="10%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ');"><img src="../imagens/excluir.png" border="0"></a></td>';
	echo '</tr>';
}
echo '</table>';

?>
    
</div>
</body>
</html>